package com.example.clicker;



import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
	private static final int REQUEST_SAVE = 0;
	private static final int REQUEST_LOAD = 1;
	boolean l,r,t,b;
	boolean bsel;
	float xff,yff,xsf,ysf;
	float xsfb,ysfb;
	int dxsize,dysize,bwidth,bheight;
	
	float maxr;
	boolean cornerdrag;
	TextView tv;
	Button btn,btnlv,btnlh,btnfl,btnrl;
	FrameLayout fl;
	Buflire<Button> bbtn;
	Buflire<FrameLayout> bflbtn;
	Buflire<LinearLayout> blvbtn;
	Buflire<LinearLayout> blhbtn;
	Buflire<RelativeLayout> brbtn;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		l=r=t=b=false;
		bsel=false;
		cornerdrag=false;
		xsfb=ysfb=0;
		//bweight=0;
		setContentView(R.layout.activity_main);
		
		fl=(FrameLayout)findViewById(R.id.frameLayout1);
	
		btnlv = (Button)findViewById(R.id.blv);
		btnlh = (Button)findViewById(R.id.blh);
		btnfl = (Button)findViewById(R.id.bfl);
		btnrl = (Button)findViewById(R.id.brl);
		btn = (Button)findViewById(R.id.btn);
	
		ContextThemeWrapper newContext = new ContextThemeWrapper(this, R.style.btn_simple_digit_key_border);
		bbtn= new Buflire<Button>(newContext,android.R.drawable.btn_default, R.drawable.listll,Buflire.BUTTON_TYPE);
		bbtn.vbtn.setOnTouchListener(bbtn.GetOnTouch());
		bbtn.vbtn.setOnLongClickListener(bbtn.GetOnLongClick());

		bflbtn = new Buflire<FrameLayout>(newContext, android.R.drawable.btn_default, R.drawable.listll,Buflire.FRAME_LAYOUT_TYPE);
		bflbtn.vbtn.setOnTouchListener(bflbtn.GetOnTouch());
		bflbtn.vbtn.setOnLongClickListener(bflbtn.GetOnLongClick());
		
		blvbtn = new Buflire<LinearLayout>(newContext, android.R.drawable.btn_default, R.drawable.listll,Buflire.LINEAR_LAYOUT_VERTICAL_TYPE);
		blhbtn = new Buflire<LinearLayout>(newContext, android.R.drawable.btn_default, R.drawable.listll,Buflire.LINEAR_LAYOUT_HORIZONTAL_TYPE);
		brbtn = new Buflire<RelativeLayout>(newContext, android.R.drawable.btn_default, R.drawable.listll,Buflire.RELATIVE_LAYOUT_TYPE);
		
		
		
		btn.setOnClickListener(this);
		btnlv.setOnClickListener(this);
		btnlh.setOnClickListener(this);
		btnfl.setOnClickListener(this);
		btnrl.setOnClickListener(this);
		
		//btn.setOnTouchListener(this);
		//btn.setOnLongClickListener(this);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			Intent intent = new Intent(getBaseContext(), TimecodeDialog.class);
			startActivity(intent);
		
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		ContextThemeWrapper newContext = new ContextThemeWrapper(this, R.style.btn_simple_digit_key_border);
		
		switch(v.getId())
		{
		case R.id.btn:
			fl.addView(bbtn.vbtn);
		
		break;
		case R.id.blv:
			fl.addView(blvbtn.vbtn);
			
		break;
		case R.id.blh:
			fl.addView(blhbtn.vbtn);
			
		break;
		case R.id.bfl:
			fl.addView(bflbtn.vbtn);	
		break;
		case R.id.brl:
			fl.addView(brbtn.vbtn);	
			
		break;
		
		default:
		}
	}
	
	
	
	public synchronized void onActivityResult(final int requestCode,
            int resultCode, final Intent data) {

            if (resultCode == Activity.RESULT_OK) {

                    if (requestCode == REQUEST_SAVE) {
                    	Toast.makeText(getBaseContext(),"Saving...", Toast.LENGTH_LONG).show();
                    } else if (requestCode == REQUEST_LOAD) {
                    	Toast.makeText(getBaseContext(),"Loading...", Toast.LENGTH_LONG).show();
                    }
                    
                    String filePath = data.getStringExtra(FileDialog.RESULT_PATH);
                    Toast.makeText(getBaseContext(),"Path" + filePath, Toast.LENGTH_LONG).show();
            } else if (resultCode == Activity.RESULT_CANCELED) {
            	Toast.makeText(getBaseContext(),"Cancel", Toast.LENGTH_LONG).show();
            }

    }
	
}
